﻿@using ZhouYu.NewWorld.Model
@{
    Layout = null;
    var parentCategory = ViewBag.categories as List<Backcolumn>;
    var count = ViewBag.count;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <style>
        .right {
            display: none;
        }
         .row{
    display: none;
    }
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link href="~/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/css/style.css" />
    <link href="~/assets/css/codemirror.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/assets/css/ace.min.css" />
    <link rel="stylesheet" href="~/font/css/font-awesome.min.css" />
    <link rel="stylesheet" href="~/layui-v2.5.4/layui/css/layui.css" />
    <link href="~/layui-v2.5.4/layui/css/modules/layer/default/layer.css" rel="stylesheet" type="text/css" />
    <!--[if lte IE 8]>
      <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
    <![endif]-->
    <script src="~/Scripts/jquery-1.9.1.min.js"></script>
    <script src="~/assets/js/bootstrap.min.js"></script>
    <script src="~/assets/js/typeahead-bs2.min.js"></script>
    <script src="~/assets/js/jquery.dataTables.min.js"></script>
    <script src="~/assets/js/jquery.dataTables.bootstrap.js"></script>
    <script src="~/assets/layer/layer.js" type="text/javascript"></script>
    <script src="~/assets/laydate/laydate.js" type="text/javascript"></script>
    <script src="~/Scripts/Format.js" type="text/javascript"></script>
    <script src="~/layui-v2.5.4/layui/layui.js" type="text/javascript"></script>
    <title>后台导航管理</title>
</head>

<body>
    <div class="margin clearfix">
        <div class="" id="Other_Management">
            <div class="search_style">

                <ul class="search_content clearfix">
                    <li><label class="l_f">会员名称</label><input name="" type="text" id="name" class="text_add" placeholder="输入会员名称、电话、邮箱" style=" width:400px" /></li>
                    <li style="width:90px;"><button type="button" class="btn_search" id="checkName"><i class="fa fa-search"></i>查询</button></li>
                </ul>
            </div>
            <div class="border clearfix">
                <span class="l_f">
                    <button id="AddTouristroute" class="btn btn-danger">&nbsp;添加&nbsp;</button>
                    @*<a href="javascript:ovid()" class="btn btn-danger"><i class="fa fa-trash"></i>&nbsp;批量删除</a>*@
                </span>
                <span class="l_f">
                    @*<button id="AddTouristroute" class="btn btn-danger">&nbsp;添加&nbsp;</button>*@
                    @*<a href="javascript:ovid()" class="btn btn-danger"><i class="fa fa-trash"></i>&nbsp;批量删除</a>*@
                </span>
                @*<span class="r_f">共：<b>2345</b>条</span>*@
            </div>
            <div class="right" id="app">
                <fieldset class="layui-elem-field layui-field-title">
                    <legend id="rigthName">添加用户</legend>
                </fieldset>
                <div>
                    <form class="layui-form ">
                        <input type="hidden" value="" name="BackColumn_Id" id="BackColumn_Id" />
                        <div class="layui-form-item">
                            <label class="layui-form-label">导航名</label>
                            <div class="layui-input-block">
                                <input type="text" name="BackColumn_Name" id="BackColumn_Name" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">导航地址</label>
                            <div class="layui-input-block">
                                <input type="text" name="BackColumn_Url" id="BackColumn_Url" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                            </div>
                        </div>
                    </form>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">父级ID</label>
                    <div class="layui-input-block">
                        <select name="ParentId" id="ParentId" style="margin-left:10px">
                            <option value="0" selected=selected>顶级</option>
                            @foreach (var item in parentCategory)
                            {
                                <option value="@item.BackColumn_Id">@item.BackColumn_Name</option>
                            }
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="button" id="commit" value="立即提交" class="layui-btn" />
                    </div>
                </div>
            </div>
            <div class="list_style">
                @*<table class="table table-striped table-bordered table-hover" id="sample-table"></table>*@
                <table class="layui-hide" id="sample-table" lay-filter="demo"></table>
                <script id="barDemo" type="text/html">
                    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                    @*<a class="layui-btn layui-btn-xs" lay-event="Sev">添加</a>*@
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                </script>
            </div>

        </div>
    </div>

</body>
</html>
<script>
    //jQuery(function ($) {
    //    var oTable1 = $('#sample-table').dataTable({
    //        "aaSorting": [[1, "desc"]],//默认第几个排序
    //        "bStateSave": true,//状态保存
    //        "aoColumnDefs": [
    //            //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
    //            { "orderable": false, "aTargets": [0, 2, 3, 6] }// 制定列不参与排序
    //        ]
    //    });


    //    $('table th input:checkbox').on('click', function () {
    //        var that = this;
    //        $(this).closest('table').find('tr > td:first-child input:checkbox')
    //            .each(function () {
    //                this.checked = that.checked;
    //                $(this).closest('tr').toggleClass('selected');
    //            });

    //    });
    //});



    ///*用户-删除*/
    //function member_del(obj, id) {
    //    layer.confirm('确认要删除吗？', function (index) {
    //        $(obj).parents("tr").remove();
    //        layer.msg('已删除!', { icon: 1, time: 1000 });
    //    });
    //}
    ////积分浏览
    //function integration_history(id) {
    //    layer.open({
    //        type: 1,
    //        title: '积分获取记录',
    //        area: ['800px', '400px'],
    //        shadeClose: true,
    //        content: $('#integration_history'),
    //    })
    //    $('#integration_history_list').dataTable({
    //        "aaSorting": [[1, "desc"]],//默认第几个排序
    //        "bStateSave": true,//状态保存
    //        "aoColumnDefs": [{
    //            "bSortable": false,
    //            "orderable": false,
    //            "aTargets": [0, 1]
    //        }]
    //    });

    //};
    ////浏览记录

    //function Browse_history(id) {
    //    layer.open({
    //        type: 1,
    //        title: '浏览记录',
    //        area: ['800px', '400px'],
    //        shadeClose: true,
    //        content: $('#Browse_history'),
    //    })
    //    $('#Browse_history_list').dataTable({
    //        "aaSorting": [[1, "desc"]],//默认第几个排序
    //        "bStateSave": true,//状态保存
    //        "aoColumnDefs": [{
    //            "bSortable": false,
    //            "orderable": false,
    //            "aTargets": [0, 1]
    //        }]
    //    });
    //}


    ////购物记录
    //function Order_history(id) {
    //    layer.open({
    //        type: 1,
    //        title: '购物记录',
    //        area: ['800px', '400px'],
    //        shadeClose: true,
    //        content: $('#Order_history'),
    //    });
    //    $('#Order_history_list').dataTable({
    //        "aaSorting": [[1, "desc"]],//默认第几个排序
    //        "bStateSave": true,//状态保存
    //        "aoColumnDefs": [{
    //            "bSortable": false,
    //            "orderable": false,
    //            "aTargets": [0, 1]
    //        }]
    //    });
    //}


</script>
<script>
     //列表刷新
        function TableReload() {
            var table = layui.table;
            var name = $("#name").val();
            //上述方法等价于
            table.reload('sample-table', {
                where: { //设定异步数据接口的额外参数，任意设
                    name: name
                }
            });
        }
        //查询按钮点击事件
        $("#checkName").click(function () {
            //调用列表刷新方法
            TableReload();
        });
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;  //启用
        table.render({
            elem: '#sample-table'
            , url: '/Backcolumn/GetBackcolumnPageList'
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , cols: [[
                { type: 'checkbox' }
                , { field: 'BackColumn_Id', width: 110, align: 'center', title: '导航Id', sort: true }
                , { field: 'BackColumn_ParentId', width: 110, align: 'center', title: '父Id' }
                , { field: 'BackColumn_Name', width: 130, align: 'center', title: '导航名', sort: true }
                , { field: 'BackColumn_Url', width: 180, align: 'center', title: '导航地址' }
                , { field: 'BackColumn_UpdateTime', width: 180, align: 'center', title: '修改时间', templet: "<div>{{Format(d.BackColumn_UpdateTime,'yyyy-MM-dd')}}</div>" }
                , { field: 'BackColumn_CreateTime', width: 180, align: 'center', title: '创建时间', templet: "<div>{{Format(d.BackColumn_CreateTime,'yyyy-MM-dd')}}</div>" }
                , { fixed: 'right', title: '操作', width: 208, /*align: 'center',*/ toolbar: '#barDemo' }
            ]]
            , page: true
            , id: 'sample-table'
        });
        //删除
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            var id = data.BackColumn_Id;
            if (obj.event === 'del') {
                //删除的功能代码
                layer.confirm('真的要删除吗', function (index) {
                    $.ajax({
                        url: "/BackColumn/DelBackcolumn?id=" + id,
                        type: "Post",
                        success: function (data) {
                            if (data.Success) {
                                layer.msg('删除成功！', {
                                    title: '提示框',
                                    icon: 1,
                                    time: 2000

                                }, function () {
                                    TableReload();
                                    //layer.close(index);
                                });
                                location.reload();
                            }
                            else {
                                layer.msg('删除失败！', {
                                    title: '提示框',
                                    icon: 1,
                                    time: 2000
                                });
                            }
                        }
                    });
                });
            } else if (obj.event === 'edit') {
               //编辑
                $("#BackColumn_Id").val(data.BackColumn_Id);
                $("#ParentId").val(data.BackColumn_ParentId);
                $("#BackColumn_Name").val(data.BackColumn_Name);
                $("#BackColumn_Url").val(data.BackColumn_Url);
               // $("#BackColumn_UpdateTime").val(Format(data.BackColumn_UpdateTime, 'yyyy-MM-dd'));
                 layer.open({
                    type: 1,
                    title: '修改信息',
                    area: ['800px', ''],
                    shadeClose: false,
                    content: $("#app"),
                });
                //点击编辑将标题修改成编辑
                $("#rigthName").text("编辑");
            }
        });
    });
    $(function () {
        //打开添加路线按钮
        $("#AddTouristroute").on('click', function () {
            layer.open({
                type: 1,
                title: '添加管理员',
                area: ['700px', ''],
                shadeClose: false,
                content: $('#app'),
            });
            $("#BackColumn_Id").val(null);
            $("#BackColumn_Name").val(null);
            $("#BackColumn_Url").val(null);
            $("#rigthName").text("添加");
        });
        //添加按钮点击事件
        $("#commit").click(function () {
            var data = {};
            data.BackColumn_Id = $("#BackColumn_Id").val();
            data.BackColumn_ParentId = $("#ParentId").val();
            data.BackColumn_Name = $("#BackColumn_Name").val();
            data.BackColumn_Url = $("#BackColumn_Url").val();
            $.ajax({
                url: "/Backcolumn/AddBackcolumn",
                type: "post",
                data: data,
                success: function (result) {
                    if (result.Success) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000 //2秒关闭（如果不配置，默认是3秒）使用这个弹框那么弹框后续操作就要写在function中
                        }, function () {
                            location.reload(); window.location.href = "/Home/Backcolumn";
                        });
                    }
                    else {
                        layer.msg(result.msg);
                    }
                }
            })
        });
    });
</script>

